<!--  -->
<template>
    <div class="page-container">
        <div class="header-panel">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
                <el-form-item label="测站">
                    <StbprpSelect v-model="queryParams.stcd" placeholder="请选择测站"></StbprpSelect>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd"
                        v-hasPermi="['sjcx:hdfhzb:add']">新增</el-button>

                    <el-button type="success" plain icon="el-icon-edit" :disabled="single" @click="handleUpdate"
                        v-hasPermi="['sjcx:hdfhzb:edit']">修改</el-button>

                    <el-button type="danger" plain icon="el-icon-delete" :disabled="multiple" @click="handleDelete"
                        v-hasPermi="['sjcx:hdfhzb:remove']">删除</el-button>

                </el-form-item>
            </el-form>
        </div>

        <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" size="medium"
            height="calc(100% - 100px)">
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column label="测站编码" align="center" prop="stcd" width="90" />
            <el-table-column label="测站名称" align="center" prop="stnm" width="120" />
            <el-table-column label="左堤高程" align="center" prop="ldkel" :show-overflow-tooltip="true" />
            <el-table-column label="右堤高程" align="center" prop="rdkel" :show-overflow-tooltip="true" />
            <el-table-column label="警戒水位" align="center" prop="wrz" :show-overflow-tooltip="true" />
            <el-table-column label="警戒流量" align="center" prop="wrq" :show-overflow-tooltip="true" />
            <el-table-column label="保证水位" align="center" prop="grz" :show-overflow-tooltip="true" />
            <el-table-column label="保证流量" align="center" prop="grq" :show-overflow-tooltip="true" />
            <el-table-column label="平滩流量" align="center" prop="flpq" :show-overflow-tooltip="true" />
            <el-table-column label="实测最高水位" align="center" prop="obhtz" :show-overflow-tooltip="true" />
            <el-table-column label="实测最高水位出现时间" align="center" prop="obhtztm" :show-overflow-tooltip="true" />
            <el-table-column label="调查最高水位" align="center" prop="ivhz" :show-overflow-tooltip="true" />
            <el-table-column label="调查最高水位出现时间" align="center" prop="ivhztim" :show-overflow-tooltip="true" />
            <el-table-column label="实测最大流量" align="center" prop="obmxq" :show-overflow-tooltip="true" />
            <el-table-column label="实测最大流量出现时间" align="center" prop="obmxqtm" :show-overflow-tooltip="true" />
            <el-table-column label="调查最大流量" align="center" prop="ivmxq" :show-overflow-tooltip="true" />
            <el-table-column label="调查最大流量出现时间" align="center" prop="ivmxqtm" :show-overflow-tooltip="true" />
            <el-table-column label="历史最大含沙量" align="center" prop="hmxs" :show-overflow-tooltip="true" />
            <el-table-column label="历史最大含沙量出现时间" align="center" prop="hmxstm" :show-overflow-tooltip="true" />
            <el-table-column label="历史最大断面平均流速" align="center" prop="hmxavv" :show-overflow-tooltip="true" />
            <el-table-column label="历史最大断面平均流速出现时间" align="center" prop="hmxavvtm" :show-overflow-tooltip="true" />
            <el-table-column label="历史最低水位" align="center" prop="hlz" :show-overflow-tooltip="true" />
            <el-table-column label="历史最低水位出现时间" align="center" prop="hlztm" :show-overflow-tooltip="true" />
            <el-table-column label="历史最小流量" align="center" prop="hmnq" :show-overflow-tooltip="true" />
            <el-table-column label="历史最小流量出现时间" align="center" prop="hmnqtm" :show-overflow-tooltip="true" />
            <el-table-column label="高水位告警值" align="center" prop="taz" :show-overflow-tooltip="true" />
            <el-table-column label="大流量告警值" align="center" prop="taq" :show-overflow-tooltip="true" />
            <el-table-column label="低水位告警值" align="center" prop="laz" :show-overflow-tooltip="true" />
            <el-table-column label="小流量告警值" align="center" prop="laq" :show-overflow-tooltip="true" />
            <el-table-column label="启动预报水位标准" align="center" prop="sfz" :show-overflow-tooltip="true" />
            <el-table-column label="启动预报流量标准" align="center" prop="sfq" :show-overflow-tooltip="true" />
            <el-table-column label="操作" align="center" width="160" fixed="right" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['sjcx:hdfhzb:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['sjcx:hdfhzb:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>


        <!-- 添加或修改用户配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="1000px" :close-on-click-modal="false" append-to-body
            @close="dialogClose">
            <el-form ref="form" :model="form" :rules="rules" label-width="160px">
                <el-row :gutter="20">
                    <!-- 第一行第一列：测站编码 -->
                    <el-col :span="12">
                        <el-form-item label="测站编码" prop="stcd">
                            <StbprpSelect v-model="form.stcd" placeholder="请选择测站" :disabled="isEdit"
                                style="width: 100%;">
                            </StbprpSelect>
                        </el-form-item>
                    </el-col>

                    <!-- 第一行第二列：时间 -->
                    <el-col :span="12">
                        <!-- 左堤高程 -->
                        <el-form-item label="左堤高程" prop="ldkel">
                            <el-input v-model="form.ldkel" placeholder="请输入左堤高程（单位：m）" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 第二行 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <!-- 右堤高程 -->
                        <el-form-item label="右堤高程" prop="rdkel">
                            <el-input v-model="form.rdkel" placeholder="请输入右堤高程（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <!-- 警戒水位 -->
                        <el-form-item label="警戒水位" prop="wrz">
                            <el-input v-model="form.wrz" placeholder="请输入警戒水位（单位：m）" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 第三行 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <!-- 警戒流量 -->
                        <el-form-item label="警戒流量" prop="wrq">
                            <el-input v-model="form.wrq" placeholder="请输入警戒流量（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <!-- 保证水位 -->
                        <el-form-item label="保证水位" prop="grz">
                            <el-input v-model="form.grz" placeholder="请输入保证水位（单位：m）" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 第四行 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <!-- 保证流量 -->
                        <el-form-item label="保证流量" prop="grq">
                            <el-input v-model="form.grq" placeholder="请输入保证流量（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <!-- 平滩流量 -->
                        <el-form-item label="平滩流量" prop="flpq">
                            <el-input v-model="form.flpq" placeholder="请输入平滩流量（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 第五行 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <!-- 实测最高水位 -->
                        <el-form-item label="实测最高水位" prop="obhtz">
                            <el-input v-model="form.obhtz" placeholder="请输入实测最高水位（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <!-- 实测最高水位出现时间 -->
                        <el-form-item label="实测最高水位出现时间" prop="obhtztm">
                            <el-date-picker v-model="form.obhtztm" type="datetime" style="width: 100%;"
                                placeholder="选择时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 第六行 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <!-- 调查最高水位 -->
                        <el-form-item label="调查最高水位" prop="ivhz">
                            <el-input v-model="form.ivhz" placeholder="请输入调查最高水位（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <!-- 调查最高水位出现时间 -->
                        <el-form-item label="调查最高水位出现时间" prop="ivhztim">
                            <el-date-picker v-model="form.ivhztim" type="datetime" style="width: 100%;"
                                placeholder="选择时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>


                <el-row :gutter="20">
                    <!-- 实测最大流量 -->
                    <el-col :span="12">
                        <el-form-item label="实测最大流量" prop="obmxq">
                            <el-input v-model="form.obmxq" placeholder="请输入实测最大流量（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                    <!-- 实测最大流量出现时间 -->
                    <el-col :span="12">
                        <el-form-item label="实测最大流量出现时间" prop="obmxqtm">
                            <el-date-picker v-model="form.obmxqtm" type="datetime" style="width: 100%;"
                                placeholder="选择时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 调查最大流量 -->
                    <el-col :span="12">
                        <el-form-item label="调查最大流量" prop="ivmxq">
                            <el-input v-model="form.ivmxq" placeholder="请输入调查最大流量（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                    <!-- 调查最大流量出现时间 -->
                    <el-col :span="12">
                        <el-form-item label="调查最大流量出现时间" prop="ivmxqtm">
                            <el-date-picker v-model="form.ivmxqtm" type="datetime" style="width: 100%;"
                                placeholder="选择时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 历史最大含沙量 -->
                    <el-col :span="12">
                        <el-form-item label="历史最大含沙量" prop="hmxs">
                            <el-input v-model="form.hmxs" placeholder="请输入历史最大含沙量（单位：kg/m³）" />
                        </el-form-item>
                    </el-col>
                    <!-- 历史最大含沙量出现时间 -->
                    <el-col :span="12">
                        <el-form-item label="历史最大含沙量出现时间" prop="hmxstm">
                            <el-date-picker v-model="form.hmxstm" type="datetime" style="width: 100%;"
                                placeholder="选择时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 历史最大断面平均流速 -->
                    <el-col :span="12">
                        <el-form-item label="历史最大断面平均流速" prop="hmxavv">
                            <el-input v-model="form.hmxavv" placeholder="请输入历史最大断面平均流速（单位：m/s）" />
                        </el-form-item>
                    </el-col>
                    <!-- 历史最大断面平均流速出现时间 -->
                    <el-col :span="12">
                        <el-form-item label="历史最大断面平均流速出现时间" prop="hmxavvtm">
                            <el-date-picker v-model="form.hmxstm" type="hmxavvtm" style="width: 100%;"
                                placeholder="选择时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 历史最低水位 -->
                    <el-col :span="12">
                        <el-form-item label="历史最低水位" prop="hlz">
                            <el-input v-model="form.hlz" placeholder="请输入历史最低水位（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <!-- 历史最低水位出现时间 -->
                    <el-col :span="12">
                        <el-form-item label="历史最低水位出现时间" prop="hlztm">
                            <el-date-picker v-model="form.hlztm" type="hmxavvtm" style="width: 100%;" placeholder="选择时间"
                                format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 历史最小流量 -->
                    <el-col :span="12">
                        <el-form-item label="历史最小流量" prop="hmnq">
                            <el-input v-model="form.hmnq" placeholder="请输入历史最小流量（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                    <!-- 历史最小流量出现时间 -->
                    <el-col :span="12">
                        <el-form-item label="历史最小流量出现时间" prop="hmnqtm">
                            <el-date-picker v-model="form.hlztm" type="hmnqtm" style="width: 100%;" placeholder="选择时间"
                                format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 高水位告警值 -->
                    <el-col :span="12">
                        <el-form-item label="高水位告警值" prop="taz">
                            <el-input v-model="form.taz" placeholder="请输入高水位告警值（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <!-- 大流量告警值 -->
                    <el-col :span="12">
                        <el-form-item label="大流量告警值" prop="taq">
                            <el-input v-model="form.taq" placeholder="请输入大流量告警值（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 低水位告警值 -->
                    <el-col :span="12">
                        <el-form-item label="低水位告警值" prop="laz">
                            <el-input v-model="form.laz" placeholder="请输入低水位告警值（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <!-- 小流量告警值 -->
                    <el-col :span="12">
                        <el-form-item label="小流量告警值" prop="laq">
                            <el-input v-model="form.laq" placeholder="请输入小流量告警值（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <!-- 启动预报水位标准 -->
                    <el-col :span="12">
                        <el-form-item label="启动预报水位标准" prop="sfz">
                            <el-input v-model="form.sfz" placeholder="请输入启动预报水位标准（单位：m）" />
                        </el-form-item>
                    </el-col>
                    <!-- 启动预报流量标准 -->
                    <el-col :span="12">
                        <el-form-item label="启动预报流量标准" prop="sfq">
                            <el-input v-model="form.sfq" placeholder="请输入启动预报流量标准（单位：m³/s）" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="open = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import StbprpSelect from '@/components/Select/StbprpSelect'
export default {
    components: { StbprpSelect },
    data() {
        return {
            queryParams: {},
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 勾选元素
            selection: [],
            isEdit: false,
            // 表单参数
            form: {

            },
            // 弹出层标题
            title: "",
            dataList: [],
            open: false,
            // 表单校验
            rules: {
                stcd: [
                    { required: true, message: '请选择测站编码', trigger: 'blur' },
                ],

            },
        }
    },
    computed: {},
    created() {
        this.getList();
    },
    mounted() { },
    methods: {
        getList() {
            this.loading = true;
            this.$request({
                url: '/baseApi/st_rvfcch_b/list',
                method: 'get',
                params: {
                    ...this.queryParams
                }
            }).then((res) => {
                if (res.code === 200) {
                    this.loading = false;
                    this.dataList = res.data;
                }
            })
        },
        handleQuery() {
            this.getList();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selection = selection
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.title = "添加信息";
            this.open = true
        },
        /** 修改按钮操作 */
        async handleUpdate(row) {
            this.form = this.selection[0] || row
            this.isEdit = true
            this.title = "修改信息";
            this.open = true
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = this.selection || [row] 
            this.$confirm('是否确认删除该的数据项？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$request({
                    url: '/baseApi/st_rvfcch_b/delete',
                    method: 'post',
                    data: ids
                })
                .then(res => {
                    this.handleQuery();
                    this.$message({
                        message: '操作成功',
                        type: 'success'
                    });
                })

            }).catch(() => { })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    let url = ''
                    if (this.isEdit) {
                        url = '/baseApi/st_rvfcch_b/udpate'
                    } else {
                        url = '/baseApi/st_rvfcch_b/insert'
                    }
                    this.$request({
                        url: url,
                        method: 'post',
                        data: this.form
                    }).then((res) => {
                        if (res.code === 200) {
                            this.open = false;
                            this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                            this.handleQuery()
                        }
                    })
                }
            });
        },
        resetForm() {
            this.isEdit = false
            this.$data.form = this.$options.data().form
            this.$refs.form && this.$refs.form.resetFields()
        },
        dialogClose() {
            this.resetForm()
        }


    },
}
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类样式</style>